import {
  SetPassword,
  UploadHeadPortrait,
  ModifyProfile,
  SaveUserAddressParams
} from './paramsInterface';
import request from '../request';
import {
  SET_PASSWD_REQ,
  UPLOAD_HEAD_PORTRAIT_REQ,
  MODIFY_PROFILE_REQ,
  GET_SELF_CENTER_REQ,
  GET_USER_ADDRESS_REQ,
  SAVE_USER_ADDRESS_REQ
} from '../../service/constant';
import { CommonRes } from '../commonRes';
import { UploadHeadPortraitRes } from './uploadHeadPortrait';
import { GetSelfCenterRes } from './getSelfCenter';
import { GetUserAddressRes } from './getUserAddress';

export default {
  // 设置密码
  setPassword: (data: SetPassword): Promise<CommonRes> =>
    request({
      msgId: SET_PASSWD_REQ,
      data,
      param: { needLoading: true, needUserId: true }
    }),
  // 上传用户头像
  uploadHeadPortrait: (
    data: UploadHeadPortrait
  ): Promise<UploadHeadPortraitRes> =>
    request({
      msgId: UPLOAD_HEAD_PORTRAIT_REQ,
      data,
      param: { needLoading: true }
    }),
  // 修改用户简介
  modifyProfile: (data: ModifyProfile): Promise<CommonRes> =>
    request({
      msgId: MODIFY_PROFILE_REQ,
      data,
      param: { needLoading: true, needUserId: true }
    }),
  // 获取个人中心
  getSelfCenter: (): Promise<GetSelfCenterRes> =>
    request({
      msgId: GET_SELF_CENTER_REQ
    }),
  // 获取地址信息
  getUserAddress: (): Promise<GetUserAddressRes> =>
    request({
      msgId: GET_USER_ADDRESS_REQ
    }),
  // 保存用户地址信息
  saveUserAddress: (data: SaveUserAddressParams): Promise<CommonRes> =>
    request({
      msgId: SAVE_USER_ADDRESS_REQ,
      data
    })
};
